// ActionScript file
import com.gskinner.geom.ColorMatrix;

import flash.events.MouseEvent;

import mx.controls.Button;
import mx.controls.Image;
import mx.controls.Label;
import mx.events.SliderEvent;

public var cm:ColorMatrix = new ColorMatrix();

/**
 * 向左边栏添加调节工具
 */
private function effectControls():DisplayObject
{
	var vbox_ctr:VBox=new VBox();
	vbox_ctr.setStyle("horizontalAlign", "center");
	vbox_ctr.setStyle("textAlign", "center");
	vbox_ctr.x=0;
	vbox_ctr.y=0;
	vbox_ctr.percentWidth=100;
	//vbox_ctr.width = 220;
	vbox_ctr.percentHeight=100;
	//vbox_ctr.setStyle("backgroundColor", '0xcccccc');
	//vbox_ctr.setStyle("backgroundAlpha", 100);
	
	var label_ctr_brightness:Label=new Label();
	label_ctr_brightness.text='亮度';
	label_ctr_brightness.percentWidth=100;
	//label_ctr_brightness.x = (vbox_ctr.width - label_ctr_brightness.width)/2;
	label_ctr_brightness.x=0;
	label_ctr_brightness.setStyle("textAlign", "center");
	var hslider_ctr_brightness:HSlider=new HSlider();
	hslider_ctr_brightness.minimum=-100;
	hslider_ctr_brightness.maximum=100;
	hslider_ctr_brightness.value=0;
	hslider_ctr_brightness.percentWidth=100;
	hslider_ctr_brightness.id = 'hs_bri';
	hslider_ctr_brightness.name = 'hs_bri';
	hslider_ctr_brightness.snapInterval = 1;
	hslider_ctr_brightness.addEventListener(SliderEvent.CHANGE, function(event:SliderEvent):void{brightness_value = event.target.value;changeeffect();});
	
	var label_ctr_contrast:Label=new Label();
	label_ctr_contrast.text='对比度';
	label_ctr_contrast.percentWidth=100;
	label_ctr_contrast.setStyle("textAlign", "center");
	var hslider_ctr_contrast:HSlider=new HSlider();
	hslider_ctr_contrast.minimum=-100;
	hslider_ctr_contrast.maximum=100;
	hslider_ctr_contrast.value=0;
	hslider_ctr_contrast.percentWidth=100;
	hslider_ctr_contrast.id = 'hs_con';
	hslider_ctr_contrast.addEventListener(SliderEvent.CHANGE, function(event:SliderEvent):void{contrast_value = event.target.value;changeeffect();});
	
	var label_ctr_saturation:Label=new Label();
	label_ctr_saturation.text='饱和度';
	label_ctr_saturation.percentWidth=100;
	label_ctr_saturation.setStyle("textAlign", "center");
	var hslider_ctr_saturation:HSlider=new HSlider();
	hslider_ctr_saturation.minimum=-100;
	hslider_ctr_saturation.maximum=100;
	hslider_ctr_saturation.value=0;
	hslider_ctr_saturation.percentWidth=100;
	hslider_ctr_saturation.id = 'hs_sat';
	hslider_ctr_saturation.addEventListener(SliderEvent.CHANGE,function(event:SliderEvent):void{saturation_value = event.target.value;changeeffect()});
	
	var label_ctr_hue:Label=new Label();
	label_ctr_hue.text='色调';
	label_ctr_hue.percentWidth=100;
	label_ctr_hue.setStyle("textAlign", "center");
	var hslider_ctr_hue:HSlider=new HSlider();
	hslider_ctr_hue.minimum=-180;
	hslider_ctr_hue.maximum=180;
	hslider_ctr_hue.value=0;
	hslider_ctr_hue.percentWidth=100;
	hslider_ctr_hue.id = 'hs_hue';
	hslider_ctr_hue.addEventListener(SliderEvent.CHANGE, function (event:SliderEvent):void{hue_value = event.target.value;changeeffect();});
	
	/*
	var effectOK:Button = new Button();
	effectOK.label = '';
	effectOK.percentWidth = 100;
	effectOK.addEventListener(MouseEvent.CLICK, saveEffect);
	*/
	//翻转
	var i1:Image = new Image();
	i1.source = "assets/h.png";
	var btnh:Button = new Button();
	btnh.label = '水平翻转';
	btnh.styleName = 'h';
	btnh.width = 100;
	btnh.height = 26;
	btnh.addEventListener(MouseEvent.CLICK, function (event:MouseEvent):void{canvas1(loadedSM.application).doh();this.isOPT = 4;});
	
	var i2:Image = new Image();
	i2.source = "assets/v.png";
	var btnv:Button = new Button();
	btnv.label = '垂直翻转';
	btnv.styleName = 'v';
	btnv.height = 26;
	btnv.width = 100;
	btnv.addEventListener(MouseEvent.CLICK, function (event:MouseEvent):void{canvas1(loadedSM.application).dov();this.isOPT = 4;});

	var tip:Button = new Button();
	tip.styleName = 'tips';
	tip.setStyle('horizontalCenter', 'center');
	tip.addEventListener(MouseEvent.CLICK, gototips);
	tip.setStyle("textAlign", "center");	
	
	
	vbox_ctr.addChild(label_ctr_brightness);
	vbox_ctr.addChild(hslider_ctr_brightness);
	vbox_ctr.addChild(label_ctr_contrast);
	vbox_ctr.addChild(hslider_ctr_contrast);
	vbox_ctr.addChild(label_ctr_saturation);
	vbox_ctr.addChild(hslider_ctr_saturation);
	vbox_ctr.addChild(label_ctr_hue);
	vbox_ctr.addChild(hslider_ctr_hue);
	//vbox_ctr.addChild(effectOK);
	vbox_ctr.addChild(i1);
	vbox_ctr.addChild(btnh);
	vbox_ctr.addChild(i2);
	vbox_ctr.addChild(btnv);
	vbox_ctr.addChild(tip);
	
	
	return vbox_ctr;
}



private function changeeffect():void{
		canvas1(loadedSM.application).doeffect(brightness_value, contrast_value, saturation_value, hue_value);
		this.isOPT = 4;
}


